package com.xuan.friend.rabbit;


import com.xuan.api.domain.dto.JudgeSubmitDTO;
import com.xuan.common.core.constants.RabbitmqConstants;
import com.xuan.common.core.exception.BusinessException;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class JudgeProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMessage(JudgeSubmitDTO judgeSubmitDTO) {
        try {
            rabbitTemplate.convertAndSend(RabbitmqConstants.OJ_WORK_QUEUE, judgeSubmitDTO);
        } catch (AmqpException e) {
            log.error("生产者 JudgeProducer 消息发送异常:{}", e.getMessage());
            throw new BusinessException("mq生产消息异常");
        }
    }


}
